package com.amikomgamedev.labirinhantu;


import org.andengine.engine.camera.hud.HUD;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.util.debug.Debug;

import com.amikomgamedev.labirinhantu.game.Game_Config;
import com.amikomgamedev.labirinhantu.game.Game_Data;
import com.amikomgamedev.labirinhantu.game.Game_Define;

public class Utils implements	Game_Define,
								Game_Data
{
	public static float getRatio(float nil)
	{
		float nil_Ratio = 0;
		
		switch(Game_Config.RATIO_USE)
		{
			case RATIO_WIDTH:
				nil_Ratio = nil / RATIO_RES_WIDTH
						* RES_WIDTH;
				break;
			case RATIO_HEIGHT:
				nil_Ratio = nil / RATIO_RES_HEIGHT
						* RES_HEIGHT;
				break;
		}
		
		return nil_Ratio;
	}
	
	public static float getRatioW(float nil)
	{
		return nil / RATIO_RES_WIDTH 
				* RES_WIDTH;
	}
	
	public static float getRatioH(float nil)
	{
		return nil / RATIO_RES_HEIGHT 
				* RES_HEIGHT;
	}
	
	public static float getRatioSplitMain(float nil)
	{
		return nil / (RATIO_RES_WIDTH - RATIO_SPLIT_TASKBAR_WIDTH)
				* RES_SPLIT_MAIN_WIDTH;
	}
	
	public static void TRACE(String arg)
	{
		if(Game_Config.TRACE)
		{
			System.out.println(arg);
		}
	}
	
	public static void DEBUG(Exception arg)
	{
		if(Game_Config.DEBUG)
		{
			Debug.e(arg);
		}
	}
	
	public static TextureOptions getTextureOption()
	{
		return Game_Config.AA_ENABLE 
				? TextureOptions.REPEATING_BILINEAR
				: TextureOptions.REPEATING_NEAREST;
	}
	
	public static boolean isOnArea(
			float p_X,
			float p_Y,
			Sprite p_Shape)
	{		
		return isOnArea(
				p_X,
				p_Y,
				p_Shape.getX(),
				p_Shape.getX() + p_Shape.getWidth(),
				p_Shape.getY(),
				p_Shape.getY() + p_Shape.getHeight());
	}
	
	public static boolean isOnArea(
			float p_X,
			float p_Y,
			Sprite p_ShapeParent,
			Sprite p_Shape)
	{		
		return isOnArea(
				p_X,
				p_Y,
				p_ShapeParent.getX() + p_Shape.getX(),
				p_ShapeParent.getX() + p_Shape.getX() + p_Shape.getWidth(),
				p_ShapeParent.getY() + p_Shape.getY(),
				p_ShapeParent.getY() + p_Shape.getY() + p_Shape.getHeight());
	}
	
	public static boolean isOnArea(
			float p_X,
			float p_Y,
			Sprite p_ShapeParent,
			Rectangle p_Rec,
			Sprite p_Shape)
	{		
		return isOnArea(
				p_X,
				p_Y,
				p_ShapeParent.getX() + p_Rec.getX() + p_Shape.getX(),
				p_ShapeParent.getX() + p_Rec.getX() + p_Shape.getX() + p_Shape.getWidth(),
				p_ShapeParent.getY() + p_Rec.getX() + p_Shape.getY(),
				p_ShapeParent.getY() + p_Rec.getX() + p_Shape.getY() + p_Shape.getHeight());
	}
	
	public static boolean isOnArea(
			float p_X,
			float p_Y,
			HUD p_ShapeParent,
			Sprite p_Shape)
	{		
		return isOnArea(
				p_X,
				p_Y,
				p_ShapeParent.getX() + p_Shape.getX(),
				p_ShapeParent.getX() + p_Shape.getX() + p_Shape.getWidth(),
				p_ShapeParent.getY() + p_Shape.getY(),
				p_ShapeParent.getY() + p_Shape.getY() + p_Shape.getHeight());
	}
	
	public static boolean isOnArea(
			float p_X,
			float p_Y,
			float p_MinX,
			float p_MaxX,
			float p_MinY,
			float p_MaxY)
	{
		if(p_X > p_MinX
				&& p_X < p_MaxX
				&& p_Y > p_MinY
				&& p_Y < p_MaxY)
			return true;
		
		return false;
	}
}
